<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/26 13:39
 * Modified Time: 2019/7/26 13:39
 * Version: 2.0
 */

namespace App\Modules\Partner\Criterias;


use App\Lib\Facades\FLAuth;
use App\Lib\Utilities;
use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class GetWithdrawCriteria extends BaseCriterias
{
    private $user_id;
    private $scene;
    private $status;

    public function __construct($user_id, $scene, $status)
    {
        $this->user_id = $user_id;
        $this->scene = $scene;
        $this->status = $status;
    }

    public function apply($model, RepositoryInterface $repository)
    {
        $user_id = $this->user_id;;


        $scene = $this->scene;
        $status = $this->status;

        $model = $model
            ->select(['id', 'scene', 'status', 'amount', 'created_at'])
            ->when($scene!=3,function ($query) use ($scene){
                $query->where('scene',$scene);
            })
            ->when($status!=3,function ($query) use ($status){
                $query->where('status',$status);
            })
            ->where('user_id', $user_id)
            ->orderBy('id', 'DESC');

        return $model;
    }
}